Skip to content

fix: use httpx context manager and align transaction_hash in Twins.chat()#225

Open
crazywriter1 wants to merge 1 commit intoOpenGradient:mainfrom
crazywriter1:fix/twins-resource-management
Open

fix: use httpx context manager and align transaction_hash in Twins.chat()#225
crazywriter1 wants to merge 1 commit intoOpenGradient:mainfrom
crazywriter1:fix/twins-resource-management

Conversation

@crazywriter1
Copy link
Copy Markdown

Summary

  • Twins.chat() called httpx.post() directly without a context manager, leaving the underlying TCP connection unclosed after each request. Wrapped the HTTP call in httpx.Client() context manager to ensure proper cleanup.
  • transaction_hash was set to an empty string "", while LLM.completion() and LLM.chat() both use "external" for non-blockchain responses. Aligned to "external" for consistency across the SDK.
  • Added 3 tests covering: context manager usage verification, transaction_hash value assertion, and empty choices error handling.

Test plan

  • test_chat_uses_context_manager — verifies __enter__ and __exit__ are called
  • test_chat_returns_external_transaction_hash — asserts transaction_hash == "external"
  • test_chat_empty_choices_raises — confirms RuntimeError on empty choices
  • All existing tests in client_test.py pass

@crazywriter1
Copy link
Copy Markdown
Author

@adambalogh

…ternal' in Twins.chat()

httpx.post() was called without a context manager, leaving connections unclosed.
transaction_hash was set to empty string instead of 'external' used by LLM class.

Signed-off-by: crazywriter1 <crazywriter1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant